package com.sense.kukoo.biz_messages.view

import android.view.View
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.gyf.immersionbar.ImmersionBar
import com.sense.kukoo.biz_messages.R
import com.sense.kukoo.biz_messages.databinding.BizMessagesActivityMessagesBinding
import com.sense.kukoo.biz_messages.vm.MessagesViewModel
import com.sense.kukoo.common.anim.BottomMotionAnimHelper
import com.sense.kukoo.common.constant.ARouterUrl
import com.sense.kukoo.common.mvvm.view.BaseMvvmActivity
import com.sense.kukoo.common.utils.ApplicationContext
import com.sense.kukoo.common.utils.DataTimeUtil
import com.sense.kukoo.lib_logger.LoggerManager

@Route(path = ARouterUrl.ROUTE_MESSAGES_MODULE_MESSAGES_ACTIVITY)
class MessagesActivity: BaseMvvmActivity<MessagesViewModel, BizMessagesActivityMessagesBinding>() {

    private val TAG: String = javaClass.simpleName
    private val mAnimHelper = BottomMotionAnimHelper()

    override fun responseVM(action: Int) {}

    override fun getLayoutId(): Int = R.layout.biz_messages_activity_messages

    override fun getViewModelClass(): Class<MessagesViewModel> = MessagesViewModel::class.java

    override fun initStatusBar() {
        ImmersionBar.with(this)
            .transparentStatusBar()
            .navigationBarColor(com.sense.kukoo.common_design.R.color.bg_background)
            .statusBarDarkFont(true)
            .navigationBarDarkIcon(true)
            .fitsSystemWindows(false)
            .init()
    }

    override fun initData() {
        mBinding.lifecycleOwner = this
        mBinding.vm = mViewModel
        //
        bindAction(mViewModel.action_back){
            mAnimHelper.animateToFinish()
        }
        bindAction(mViewModel.action_toLikesPage){
            ARouter.getInstance()
                .build(ARouterUrl.ROUTE_MESSAGES_MODULE_MESSAGES_LIKES_ACTIVITY)
                .withString(ARouterUrl.KEY_FROM, "${it}")
                .navigation()
        }
        bindAction(mViewModel.action_toFollowersPage){
            ARouter.getInstance()
                .build(ARouterUrl.ROUTE_MESSAGES_MODULE_MESSAGES_FOLLOWERS_ACTIVITY)
                .withString(ARouterUrl.KEY_FROM, "${it}")
                .navigation()
        }
        bindAction(mViewModel.action_toCommentsPage){
            ARouter.getInstance()
                .build(ARouterUrl.ROUTE_MESSAGES_MODULE_MESSAGES_COMMENTS_ACTIVITY)
                .withString(ARouterUrl.KEY_FROM, "${it}")
                .navigation()
        }
        bindAction(mViewModel.action_toSystemsPage){
            ARouter.getInstance()
                .build(ARouterUrl.ROUTE_MESSAGES_MODULE_MESSAGES_SYSTEMS_ACTIVITY)
                .withString(ARouterUrl.KEY_FROM, "4")
                .navigation()
        }
        bindAction(mViewModel.action_toCreatorsPage){
            ARouter.getInstance()
                .build(ARouterUrl.ROUTE_MESSAGES_MODULE_MESSAGES_SYSTEMS_ACTIVITY)
                .withString(ARouterUrl.KEY_FROM, "5")
                .navigation()
        }
        bindData(mViewModel.data_likes){
            if(it > 0){
                mBinding.llNumberLikes.visibility = View.VISIBLE
                mBinding.tvNumberLikes.text = "${it}"
            } else {
                mBinding.llNumberLikes.visibility = View.INVISIBLE
            }
        }
        bindData(mViewModel.data_followers){
            if(it > 0){
                mBinding.llNumberFollowers.visibility = View.VISIBLE
                mBinding.tvNumberFollowers.text = "${it}"
            } else {
                mBinding.llNumberFollowers.visibility = View.INVISIBLE
            }
        }
        bindData(mViewModel.data_comments){
            if(it > 0){
                mBinding.llNumberComments.visibility = View.VISIBLE
                mBinding.tvNumberComments.text = "${it}"
            } else {
                mBinding.llNumberComments.visibility = View.INVISIBLE
            }
        }
        bindData(mViewModel.data_systems){
            if(it > 0){
                mBinding.llNumberSystem.visibility = View.VISIBLE
                mBinding.tvNumberSystem.text = "${it}"
            } else {
                mBinding.llNumberSystem.visibility = View.GONE
            }
        }
        bindData(mViewModel.data_creators){
            if(it > 0){
                mBinding.llNumberCreator.visibility = View.VISIBLE
                mBinding.tvNumberCreator.text = "${it}"
            } else {
                mBinding.llNumberCreator.visibility = View.GONE
            }
        }
        bindData(mViewModel.data_systemsFirst){
            if(it == null){
                mBinding.itemSystem.visibility = View.GONE
            } else {
                mBinding.itemSystem.visibility = View.VISIBLE
                mBinding.tvTimeSystem.text = DataTimeUtil.dateTransform1(it.createdAt)
                mBinding.tvContentSystem.text = it.content
            }
        }
        bindData(mViewModel.data_creatorsFirst){
            if(it == null){
                mBinding.itemCreator.visibility = View.GONE
            } else {
                mBinding.itemCreator.visibility = View.VISIBLE
                mBinding.tvTimeCreator.text = DataTimeUtil.dateTransform1(it.createdAt)
                mBinding.tvContentCreator.text = it.content
            }
        }
    }

    override fun initView() {
        //弹出动画
        val first = ApplicationContext.dp2px(800F).toFloat()
        mAnimHelper.init(mBinding.flBgRoot, mBinding.clContentRoot, first){ finish() }
        mAnimHelper.animateToStart()
        //
        mViewModel.initData()
    }

    override fun onBackPressed() {
        mAnimHelper.animateToFinish()
    }
}